package org.thattoolkit.srvctl;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.commons.lang.NotImplementedException;

public class UnixOperatingSystem extends AbstractOperatingSystem {
	private void checkLSBRelease() throws IOException, InterruptedException {
		SimpleCommand result = new SimpleCommand("lsb_release","-a");
		result.execute();
		if(result.getReturnCode() == 0) {
			for(String cl : result.getOutput()) {
				String parts[] = cl.split(":", 1);
				String name = parts[0].trim();
				if(name == "Distributor ID")
					props.setProperty("os.distributor", parts[1].trim());
				else if(name == "Release") 
					props.setProperty("os.release", parts[1].trim());
				else if(name == "Codename")
					props.setProperty("os.codename", parts[1].trim());
			}
			props.setProperty("os.name", "GNU/Linux");
		}
	}
	
	private void checkUname() {
		String prop = SimpleCommand.singleLineCommand("uname","-o");
		if(!prop.isEmpty())
			props.setProperty("os.name", prop);
		prop = SimpleCommand.singleLineCommand("uname","-r");
		if(!prop.isEmpty()) 
			props.setProperty("os.version", prop);
		prop = SimpleCommand.singleLineCommand("uname","-m");
		if(!prop.isEmpty())
			props.setProperty("os.machine", prop);
	}
	
	public UnixOperatingSystem() {
		checkUname();
		checkLSBRelease();
		String cmd = FindCommand("sysctl");
	}
	
	@Override
	public void shutdown() {
		// TODO Auto-generated method stub
		throw new NotImplementedException("System not yet supported");
	}

	@Override
	public void reboot() {
		// TODO Auto-generated method stub
		throw new NotImplementedException("System not yet supported");
	}

	@Override
	public String[] getServices() {
		// TODO Auto-generated method stub
		throw new NotImplementedException("System not yet supported");
	}

	@Override
	public Service getService(String service) {
		// TODO Auto-generated method stub
		throw new NotImplementedException("System not yet supported");
	}

}
